﻿//选中状态下下拉框改变事件

function chooiceGoods(obj,pid){
	if($(".choose-name").find("i").hasClass("hschs")){
		//当前选中的才去改变
		if(pid == $(".choose-name .hschs").attr("id")){
			var filmproductid  = $(".choose-name .hschs").attr("id");
			var filmproductprice  = $(".choose-name .hschs").attr("price");
			var pquantity = "";
			if(filmproductid!=null && filmproductid!="" && filmproductid!="undefined"){
				pquantity = $("#pquantity"+filmproductid).val();
			}
			var mpamount = Math.round(filmproductprice*pquantity*100)/100;
			$("#maipingamount").html(mpamount);
			var priceForUserStr = parseFloat($("#priceForUserStr").html());
			var discount = $("#discount").val();
			priceForUserStr = parseFloat(priceForUserStr)-parseFloat(discount);
			$("#priceForUserAllStr").html(accAdd(mpamount,priceForUserStr.toFixed(1)));
		}
	}
}
$(function() {
	//卖品收起显示更多按钮
	$("#moremp").click(function() {
		if($("#moremp").val()=="- 收起"){
		   $("#moremp").val("+ 更多卖品");
		   $(".mt10.zk").addClass("none");
		}else {
			$("#moremp").val("- 收起");
			$(".mt10.zk").removeClass("none");
		}
	});
	//卖品选择
	$(".choose-name").click(function(){
		var now=$(this);
		var mpamount = 0;
		//取消
		if(now.find("i").hasClass("hschs")){
			now.find("i").attr("class","notchs");
		//选中
		}else{
			$(".choose-name").find(".hschs").attr("class","notchs");//该行注释掉表示多选
			now.find("i").attr("class","hschs");
		}
		$(".choose-name .hschs").each(function(){
			var filmproductid  = $(this).attr("id");
			var filmproductprice  = $(this).attr("price");
			var pquantity = "";
			if(filmproductid!=null && filmproductid!="" && filmproductid!="undefined"){
				pquantity = $("#pquantity"+filmproductid).val();
			}
			mpamount =mpamount + Math.round(filmproductprice*pquantity*100)/100;
		});
		$("#maipingamount").html(mpamount);
		var priceForUserStr = parseFloat($("#priceForUserStr").html());
		var discount = $("#discount").val();
		priceForUserStr = parseFloat(priceForUserStr)-parseFloat(discount);
		$("#priceForUserAllStr").html(accAdd(mpamount,priceForUserStr.toFixed(1)));
	});
	
	$(".choose-session .seatmin").mouseover(function(){
	    var seqNo = $(this).attr("id");
		var url = ticket_host + "/jquery-first026.html?id="+seqNo;
		$.post(url,null,function(data){
		    var result = data.getElementsByTagName("item");
		    var bool = result[0].childNodes[0].nodeValue;
		    var $tip=$(bool);
			$("body").append($tip);			
		})
	}).mousemove(function(e){
	    $("#tip").show();
		$('#tip').css({"top":(e.pageY-20)+"px","left":(e.pageX+30)+"px"});
	}).mouseout(function(){
		$('#tip').remove();
	});
	
	 //座位划动提示座位情况
	$(".choose-session .seatmin 11").hover(function(){
		var seqNo = $(".choose-session.seatmin").attr("id");
		alert(seqNo);
		var nowli=$(this).parents("li");
		var seatstate=$(this).parent("span").siblings(".seatstt");
		console.log(seatstate.html());
		$(".seatstt").hide();
		$(".choose-session").find("li").css("position","static");
		nowli.css("position","relative");		
		if(seatstate.css("display")=="none"){
			seatstate.show();
		}
	},function(){
		$(".seatstt").hide();
	})
	
	
	
	
	
	
$("#popup").click(function(){
		$('#popup').hide();
		$('#popup2').show();
	})
$("#popup2").click(function(){
		$('#popup2').hide();
		$('#popup3').show();
	})
$("#popup3").click(function(){
		$('#popup3').hide();
		$('#popup4').show();
	})
$(".zero_chose img").click(function(){
		$('#popup1').show();
	})

	$("#prompt").click(function(){
		$(".shadow_prt").hide()
	})
	$("#sq").click(function() {
		if($("#sq1").html()=="收起"){
		   $("#sq1").html("展开");
		   $("#sq0").html("&lt;");
		   $("#ypxx").animate({height: 0}, "200",function(){
		   		$(this).css({"border":"none","overflow":"hidden"});
		   });
		   var mb_top=parseInt($("#bla_bac").css("top"))-103;
		}else {
			$("#sq1").html("收起");
			$("#sq0").html("&gt;");
			$("#ypxx").css({"border":"1px dashed #d7d7d7","border-right":"none","overflow":"visible"}).animate({height: "100px"}, "200");
			var mb_top=parseInt($("#bla_bac").css("top"))+103;
		}
		$("#bla_bac").animate({"top":mb_top}, "200");
	});
	$("#yg").click(function() {
	    $("#popup0").show();
	});
//更换场次 
var othercc=$(".choose-session ul li").length;
if(othercc>6){
	for(var i=6;i<othercc;i++){
		$(".choose-session ul li").eq(i).hide();
	}
}
	$("#yyh").click(function() {
		if ($("#yyh").val() == "+ 展开全部") {
			$("#yyh").val("- 收起");
			$(".choose-session ul li").show();
		} else {
			$("#yyh").val("+ 展开全部");			
			if(othercc>6){
				for(var i=6;i<othercc;i++){
					$(".choose-session ul li").eq(i).hide();
				}
			}
		}
	});
});
$(document).ready(function() {
	$("#ghBtn").click(function() {
		if($(".choose-session").css("display")=="none"){
			$(".choose-session").slideDown(200);
		}
		else{
			$(".choose-session").slideUp(200);
		}
	});
	$("#gb").click(function() {
		$(".choose-session").slideUp(200);
	});
	$(document).click(function(e){
		var target = $(e.target); 
		if(target.closest("#ghcc").length == 0){ 
			$(".choose-session").hide(); 
		}
    });
	$(".choose-pack").click(function(){
		var chsitem=$(this).find("ul");
		if(chsitem.css("display")=="none"){
			chsitem.show();
		}	
	})
});
$("#tjdd1").click(function(){
	$('#nr0yg').show();
	$('#bla_bac').show();
})
//右边局顶
$(function(){ 
	var rightTop = $("#right").offset().top;
	$(window).scroll(function() {
		var sTop = $(window).scrollTop();//得到滚动条距离顶部的px值
		var leftHt = $("#leftCt").height();
		var rightHt = $("#right").height();
		if(leftHt>rightHt){
			if (rightTop < sTop) {
				var maxtop=rightTop+leftHt-rightHt;
				var prtop=leftHt-rightHt-18;
				if(sTop<maxtop){
					$("#right").css({"margin-top":sTop-rightTop});
				}
				else{
					$("#right").css({"margin-top":prtop});
				}
			}
			 else {
				$("#right").css({"margin-top":0});
			}
		}
	});
	
});
$(".popup i").click(function() {
	$(".mask").hide();
	$(".popup").hide();
});
$(".popup .closepp").click(function(){
	$(".mask").hide();
	$(".popup").hide();
	spider0yuan.pupclose();
});
$(document).click(function(e){
    var target = $(e.target); 
    if(target.closest(".choose-red").length == 0){   //除了#ghcc以外部分
        $(".choose-red-list").hide();   //弹出的部分隐藏
    }
});
$(".choose-icon-xl1").click(function(){
	var chsitem=$(this).parents("div.choose-red");
	var s = chsitem.find("ul");
	if(s.css("display")=="none"){
		s.show();
	}else if(s.css("display")=="block"){
		s.hide();
	}	
})
$(".choose-red-list a").click(function(e){
	e.preventDefault();
	var chstxt=$(this).text();
	$("#activityTitle").text(chstxt);
	var seatCount = $("#seatCount").val();
	$("#activityId").val($(this).attr("data-id"));
	if(seatCount>0){
		loadActivity($(this).attr("data-id"),$(this).attr("data-seqNo"));
	}
	 $(".choose-red-list").hide();
})

var activityFlag = $("#activityFlag").val();
	if("true"==activityFlag){
		var activityId = $("#activityId").val();
		$('a[name=yhList]').each(function(){
			var value = $(this).attr("data-id");
			if(activityId==value){
				$(this).click();
			}
		});
}
//选择优惠活动计算价格
function loadActivity(activityid,seqNo){
	if(activityid=="" || activityid==null){
		$("#activityFlag").val("false");
		$("#activityId").val("");
		$("#discount").val("0");
		$("#errorInfo").text("")
		calculateAmount();
		return;
	}
	var seatCount = $("#seatCount").val();
	if(typeof(seatCount)=="undefined"){
		return;
	}else if(seatCount==0){
		$("#discount").val("0");
		calculateYHAmount();
		return;
	}
	
	var url_remote = ticket_host + "/jquery-second043.html?activityid="+activityid+"&seqNo="+seqNo+"&ticketCount="+seatCount;
	url_remote = encodeURI(url_remote);
 	$.post(url_remote, null, function(data){
 		var result = data.getElementsByTagName("items");
		var data = result[0].childNodes[0].nodeValue;
 		if(data.indexOf("|")!=-1){
 			var flag = data.split("|")[0];
 			if("true"==flag){
 				$("#discount").val(data.split("|")[1]);
 	 			$("#activityId").val(activityid);
 	 			$("#errorInfo").text("");
 	 			calculateYHAmount();
 			}else{
 				$("#errorInfo").text(data.split("|")[1])
 				$("#discount").val("0");
 				$("#activityId").val(activityid);
 				calculateYHAmount();
 			}
 			$("#activityFlag").val("true");
 		}else{
 			$("#activityFlag").val("false");
 			$("#activityId").val("");
 			$("#discount").val("0");
 			$("#errorInfo").text("");
 		}
 	});
}
